package com.decelo.jpa.handler;

import com.decelo.jpa.result.Result;
import com.decelo.jpa.result.ResultCode;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author :JronZhang Create_Time:2019-12-29 20:07
 */
@RestControllerAdvice
public class GobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public Result bindException(MethodArgumentNotValidException methodException){
        Result result=new Result(ResultCode.CODE_401.getCode(),ResultCode.CODE_401.getMsg(),methodException.getBindingResult().getFieldError().getDefaultMessage());
        return result;
    }


}
